package com.alcatel_lucent.osp.model;

import org.apache.struts2.json.annotations.JSON;

import javax.persistence.*;
import java.sql.Timestamp;
import java.util.Date;

/**
 * Created with IntelliJ IDEA.
 * User: guoshunw
 * Date: 13-8-23
 * Time: 下午5:40
 */

@Entity
@Table(name = "ATTACHMENT")
public class Attachment extends BaseEntity {
    private String name;
    private long size;
    private byte[] content;

    private Timestamp createTime=new Timestamp(System.currentTimeMillis());
    private String digest;
    private String description;

    private Request request;

    @JSON(format = "yyyy-MM-dd HH:mm:ss")
    @Column(name = "CREATE_TIME")
    public Timestamp getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Timestamp createTime) {
        this.createTime = createTime;
    }

    @ManyToOne
    @JoinColumn(name = "REQUEST_ID")
    public Request getRequest() {
        return request;
    }

    public void setRequest(Request request) {
        this.request = request;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "IdAttachmentGenerator")
    @SequenceGenerator(name = "IdAttachmentGenerator",  sequenceName = "ID_ATTACHMENT")
    @Override
    public Long getId() {
        return super.getId();
    }

    public Attachment() {
    }

    public Attachment(String name, long size, byte[] content) {
        this.name = name;
        this.size = size;
        this.content = content;
    }

    @Column(name = "CONTENT")
    @Lob
    public byte[] getContent() {

        return content;
    }

    public void setContent(byte[] content) {
        this.content = content;
    }

    @Column(name = "DESCRIPTION")
    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @Column(name = "NAME")
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column(name = "SIZE")
    public long getSize() {
        return size;
    }

    public void setSize(long size) {
        this.size = size;
    }

    @Column(name = "DIGEST")
    public String getDigest() {
        return digest;
    }

    public void setDigest(String digest) {
        this.digest = digest;
    }


}
